1
bash
This demonstrates command-line option parsing using a while
loop and case
statement in Bash.
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in -V | --version ) echo "$version" exit ;; -s | --string ) shift; string=$1 ;; -f | --flag ) flag=1 ;; esac; shift; done if [[ "$1" == '--' ]]; then shift; fi
bash internalflow controlloopswhile
loopcommand-line parsing